﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RMS.Manage.Web.Controllers;
using RMS.BLL;
using RMS.EF.Model;
using RMS.Common;

namespace RMS.Manage.Web.Areas.RMS.Controllers
{
    [RMSAuthorize]
    public class ConfigController : BaseController
    {
        ConfigBll bll = new ConfigBll();
        /// <summary>
        /// 列表页
        /// </summary>
        /// <returns></returns>
        public ActionResult List()
        {
            return View();
        }
        /// <summary>
        /// 列表分页查询
        /// </summary>
        /// <param name="searchModel">筛选条件</param>
        /// <returns></returns>
        public ActionResult ListGetData(S_RMS_Config searchModel)
        {
            PageParamsT<S_RMS_Config> page = SetPageParams(searchModel);
            var result_p = bll.GetByPage(page);
            if (!result_p.IsSuccess)
            {
                return Json(result_p);
            }
            var result = SetPageJson(page, result_p.Data);
            return Json(result);
        }
        /// <summary>
        /// 删除和批量删除
        /// </summary>
        /// <param name="id">Id字符串","分隔</param>
        /// <returns></returns>
        public ActionResult Delete(string id)
        {
            var result = bll.Delete(id);
            return Json(result);
        }
        /// <summary>
        /// 编辑页
        /// </summary>
        /// <param name="id">数据Id</param>
        /// <param name="parentId">父节点Id</param>
        /// <param name="programId">项目Id</param>
        /// <returns></returns>
        public ActionResult Edit(string id, string parentId, string programId)
        {
            RMS_Config model = new RMS_Config();
            if (!string.IsNullOrWhiteSpace(id))
            {
                var result = bll.GetById(id);
                if (!result.IsSuccess)
                {
                    ViewBag.ErrorMsg = result.Message;
                }
                else
                {
                    model = result.Data;
                }
            }
            return PartialView(model);
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="model">编辑后的实体</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Edit(RMS_Config model)
        {
            var result = new CommonOutPutVm();
            model.LastUpdateUser = UserId;//记录操作人
            if (string.IsNullOrWhiteSpace(model.Id))
            {
                result = bll.Add(model);
            }
            else
            {
                result = bll.Updata(model);
            }
            return Json(result);
        }
    }
}